package com.uit.gis.pojo;

import com.uit.gis.util.JsonData;
import com.uit.gis.util.Util.SpatialType;

import processing.data.JSONArray;
import processing.data.JSONObject;

public class Point extends Shape{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JSONArray points = new JSONArray();
	public void setup(){ 
	  background(255);
	  spatialType = SpatialType.POINT;
	}

	
	public void draw() {
	  stroke(0); 
	  for (int i = 0; i < points.size(); i++) {
	    JSONObject vertex = points.getJSONObject(i);
	    point(vertex.getInt("x"), vertex.getInt("y"));
	  }
	}

	public void mousePressed() {
	  JSONObject vertex = new JSONObject();
	  vertex.setInt("x", mouseX);
	  vertex.setInt("y", mouseY);
	  points.append(vertex);
	}

//	public void keyPressed() {
//	  if (points.size() > 0) {
//	    saveJSONArray(points, "points");
//	    exit();
//	  }
//	}
	@Override
	public void mouseClicked(processing.event.MouseEvent e) {
		if (e.getButton() == processing.core.PConstants.RIGHT) {
			//saveJSONArray(points, "points.json");
			//continueDraw = false;
			saveToTextFile();
		}
		 
	}

	@Override
	public void saveToTextFile() {
		// TODO Auto-generated method stub
		saveJSONArray(points,  getSavingPath());
		super.saveToTextFile();
	};
	@Override
	public JsonData loadDataFromFile() {
		// TODO Auto-generated method stub
		JSONArray jsonArray = loadJSONArray(getSavingPath());
		JsonData jsonData = new JsonData(jsonArray, null);
		return jsonData;
	};

}
